/**
 * Created by wenchuan.li on 2018/6/14 11:24.
 */
define(function () {

    var self,
        app = win.app,vue,
        customersArg,
        cdata = {
            GWBINAME:'',//商机主题ID
            GWBIID:'',//客户编号
            GWBISEQ:'',//项序
            GWBI001:'',//客户角色
            GWBI002:'',//姓名
            GWBI003:'',//电话
            GWBI004:'Y',//是否在职
            GWBI005:'',//职务
            GWBI006:'',//电子邮件
            GWBI007:'',//办公电话
            GWBI008:'',//传真
            GWBI009:'',//微信号码
            GWBI010:'',//性别
            GWBI011:'',//备注
        },
        g_js = [], //角色
        g_zw = [] //职位
    ;

    var Bfradd = app.Module.extend({

        init: function () {
            self = this;
            var mainjs = app.pageModule('p_main');
            // g_js = mainjs.juese;
            // g_zw= mainjs.zhiwei;

            self._super({
                _readyBefore: function () {
                    customersArg = self._pageParameters;
                    cdata.GWBINAME = customersArg.GWBINAME;
                    cdata.GWBIID = customersArg.GWBIID;
                }
            }, win);


        },
        subData: function () {
            app.ajax({
                xurl: "api/wx/gwat161/bfrAdd",
                loading: true,
                before:function () {
                    if(cdata.GWBI002==''){
                        return '人员姓名不能为空';
                    }
                    if(cdata.GWBI003==''){
                        return '手机号码不能为空';
                    }
                },
                xdata: cdata,
                confirm:{
                    msg:'是否提交信息？'
                },
                cb: function (result) {
                    if (result.ok) {
                        app.alert({
                            msg: '添加成功！',
                            ok: function () {
                                customersArg.cb(cdata);
                                app.back(1);
                            }
                        });

                    }
                }
            });
        },
        getJs: function () {//角色列表
            app.ajax({
                xurl: "api/wx/gwa/getJs",
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        g_js.pushArray(data.data, true);
                    }
                }
            });
        },
        getZw: function () {//职位列表
            app.ajax({
                xurl: "api/wx/gwa/getZw",
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        g_zw.pushArray(data.data, true);
                    }
                }
            });
        },
        _lazy: function () {
            this._super();
            self.getJs();
            self.getZw();
        },
        _ready: function () {
            vue = new Vue({
                el: doc.querySelector('.mui-content'),
                data: {
                    sub: cdata,
                    g_js: g_js,
                    g_zw: g_zw,
                    select:false
                },
                methods: {
                    addData: function () {
                        self.subData();
                    },
                    blurOpen:function () {
                        vue.select = true;

                    },
                    chooseValue:function(p){
                        cdata.GWBI005 = p.GWBDL003;
                        vue.select = false;
                    },
                    selected:function () {
                        vue.select = false;
                    }
                }
            });

            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005
            });
        }
    });

    new Bfradd();

});